import { ApiProperty } from '@nestjs/swagger';
import {
  Column,
  CreateDateColumn,
  Entity,
  PrimaryGeneratedColumn,
} from 'typeorm';

@Entity()
export class Log {
  @ApiProperty({ type: Number, description: 'id' })
  @PrimaryGeneratedColumn()
  public id: number;

  @ApiProperty({ type: String, description: '请求方式' })
  @Column({
    type: 'varchar',
    length: 20,
    comment: '请求方式',
  })
  public method: string;

  @ApiProperty({ type: String, description: '地址' })
  @Column({
    type: 'varchar',
    comment: '地址',
  })
  public url: string;

  @ApiProperty({ type: String, description: 'ip' })
  @Column({
    type: 'varchar',
    comment: 'ip',
    nullable: true,
  })
  public ip: string;

  @ApiProperty({ type: String, description: '请求参数' })
  @Column({
    type: 'text',
    comment: '请求参数',
    nullable: true,
  })
  public data: string;

  @ApiProperty({ type: Number, description: 'http状态码' })
  @Column({
    type: 'int',
    comment: 'http状态码',
    nullable: true,
  })
  public status: number;

  @ApiProperty({ type: Date, description: '时间' })
  @CreateDateColumn({
    type: 'timestamp',
    comment: '时间',
    nullable: true,
  })
  public time: Date;

  @ApiProperty({
    type: String,
    description: '操作人',
  })
  @Column({
    type: 'varchar',
    length: 20,
    comment: '操作人',
    nullable: true,
  })
  public operator: string;

  constructor(partial?: Partial<Log>) {
    Object.assign(this, partial);
  }
}
